import logging
from ats.conf import settings

# -----------------------------------------------------------------------------
# Globals
# -----------------------------------------------------------------------------
conf = settings.get_config()
logger = None

# -----------------------------------------------------------------------------
# Log wrapper
# -----------------------------------------------------------------------------
def get_logger(level=logging.DEBUG):
	""" This works well with mod_python prefork but is not thread safe.
	"""
	global logger, conf
	if not logger:
		logger = logging.getLogger()
		hdlr = logging.FileHandler(conf.get('log', 'file'))
		formatter = logging.Formatter(conf.get('log', 'format', raw=1))
		hdlr.setFormatter(formatter)
		logger.addHandler(hdlr) 
		logger.setLevel(level)
	return logger
	

